#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>

using namespace std;

class Point;
class Complex;


class Point{
public:
    Point():x(0), y(0){}
    Point(int x, int y):x(x), y(y){}

    friend class Complex;
    friend ostream &operator<<(ostream &os, const Point &rhs);
#if defined (COM)
    operator Complex();
#endif
private:
    int x;
    int y;
};

class Complex{
public:
    Complex():rea(0), vir(0){}
    Complex(int rea, int vir):rea(rea), vir(vir){}
#if defined (ECOPY)
    Complex(Point&);
#endif
    //operator Point();

#if defined (EQUAR)
    Complex &operator=(Point &rhs){
        cout<<"Complex &operator=(Point &rhs)"<<endl;
        rea = rhs.x;
        vir = rhs.y;
        return *this;
    }
#endif
    friend class Point;
    friend ostream &operator<<(ostream &os, const Complex &rhs);

private:
    int rea;
    int vir;
};


ostream &operator<<(ostream &os, const Point &rhs){
    return os<<"("<<rhs.x<<","<<rhs.y<<")";
}

ostream &operator<<(ostream &os, const Complex &rhs){
    os<<rhs.rea;
    if(rhs.vir>0){
        os<<"+"<<rhs.vir;
    }else if(rhs.vir<0){
        os<<"-"<<rhs.vir;
    }
    return os;
}

#if defined (ECOPY)
Complex::Complex(Point &rhs){
    cout<<"Complex(Point &rhs)"<<endl;
    rea = rhs.x;
    vir = rhs.y;
}
#endif
#if defined (COM)

   Point::operator Complex(){
   cout<<"operator Complex()"<<endl;
   return Complex(x, y);
   }
/*
   Complex::operator Point(){
   cout<<"operator Point()"<<endl;
   return Point(rea, vir);
   }
*/
#endif   


int main()
{
    Point pt(8,9);
    Complex cx(4,6);
    cx = pt;
    cout<<cx<<endl;
    return 0;
}

